 #include "linux_def.h"
#include "core.h"


int shmtx_create(shmtx_t *mtx, void *addr, char *name)
{
	if (mtx->name) {
		if (strcmp(name, mtx->name) == 0) {
			mtx->name = name;
			return E_OK;
		}

		shmtx_destory(mtx);
	}

	mtx->fd = open(name, O_RDWR|O_CREAT, 0644);

	if (mtx->fd == -1) {
		fprintf(stderr, "create shmtx file failed.\n");
		return E_FAIL;
	}

	if (unlink(name) == -1) {
		fprintf(stderr, "unlink shmtx file failed.\n");
		return -1;
	}

	mtx->name = name;

	return E_OK;
}

void shmtx_destory(shmtx_t *mtx)
{
	close(mtx->fd);
}
